<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE InterruptibleFFI #-}</span><span>
</span><span id="line-3"></span><span class="hs-pragma">{-# LANGUAGE LambdaCase #-}</span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# LANGUAGE MultiWayIf #-}</span><span>
</span><span id="line-5"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude #-}</span><span>
</span><span id="line-6"></span><span>
</span><span id="line-7"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Lock</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-8"></span><span>    </span><span class="annot"><a href="GHC.IO.Handle.Lock.Common.html#FileLockingNotSupported"><span class="hs-identifier">FileLockingNotSupported</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-9"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Lock.Common.html#LockMode"><span class="hs-identifier">LockMode</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-10"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Lock.html#hLock"><span class="hs-identifier">hLock</span></a></span><span>
</span><span id="line-11"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Lock.html#hTryLock"><span class="hs-identifier">hTryLock</span></a></span><span>
</span><span id="line-12"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Lock.html#hUnlock"><span class="hs-identifier">hUnlock</span></a></span><span>
</span><span id="line-13"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">


#include &quot;HsBaseConfig.h&quot;
</span><span>
</span><span id="line-18"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Functor.html"><span class="hs-identifier">Data.Functor</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Functor.html#void"><span class="hs-identifier">void</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Lock.Common.html"><span class="hs-identifier">GHC.IO.Handle.Lock.Common</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Lock.Common.html#LockMode"><span class="hs-identifier">LockMode</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Lock.Common.html#FileLockingNotSupported"><span class="hs-identifier">FileLockingNotSupported</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html"><span class="hs-identifier">GHC.IO.Handle.Types</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier">Handle</span></a></span><span class="hs-special">)</span><span class="hs-cpp">

#if defined(mingw32_HOST_OS)
</span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Lock.Windows.html"><span class="hs-identifier">GHC.IO.Handle.Lock.Windows</span></a></span><span class="hs-cpp">
#elif HAVE_OFD_LOCKING
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Lock.LinuxOFD</span><span class="hs-cpp">
#elif HAVE_FLOCK
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Lock.Flock</span><span class="hs-cpp">
#else
</span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Lock.NoOp</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-33"></span><span class="hs-comment">-- | If a 'Handle' references a file descriptor, attempt to lock contents of the</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- underlying file in appropriate mode. If the file is already locked in</span><span>
</span><span id="line-35"></span><span class="hs-comment">-- incompatible mode, this function blocks until the lock is established. The</span><span>
</span><span id="line-36"></span><span class="hs-comment">-- lock is automatically released upon closing a 'Handle'.</span><span>
</span><span id="line-37"></span><span class="hs-comment">--</span><span>
</span><span id="line-38"></span><span class="hs-comment">-- Things to be aware of:</span><span>
</span><span id="line-39"></span><span class="hs-comment">--</span><span>
</span><span id="line-40"></span><span class="hs-comment">-- 1) This function may block inside a C call. If it does, in order to be able</span><span>
</span><span id="line-41"></span><span class="hs-comment">-- to interrupt it with asynchronous exceptions and/or for other threads to</span><span>
</span><span id="line-42"></span><span class="hs-comment">-- continue working, you MUST use threaded version of the runtime system.</span><span>
</span><span id="line-43"></span><span class="hs-comment">--</span><span>
</span><span id="line-44"></span><span class="hs-comment">-- 2) The implementation uses 'LockFileEx' on Windows and 'flock' otherwise,</span><span>
</span><span id="line-45"></span><span class="hs-comment">-- hence all of their caveats also apply here.</span><span>
</span><span id="line-46"></span><span class="hs-comment">--</span><span>
</span><span id="line-47"></span><span class="hs-comment">-- 3) On non-Windows platforms that don't support 'flock' (e.g. Solaris) this</span><span>
</span><span id="line-48"></span><span class="hs-comment">-- function throws 'FileLockingNotImplemented'. We deliberately choose to not</span><span>
</span><span id="line-49"></span><span class="hs-comment">-- provide fcntl based locking instead because of its broken semantics.</span><span>
</span><span id="line-50"></span><span class="hs-comment">--</span><span>
</span><span id="line-51"></span><span class="hs-comment">-- @since 4.10.0.0</span><span>
</span><span id="line-52"></span><span class="annot"><a href="GHC.IO.Handle.Lock.html#hLock"><span class="hs-identifier hs-type">hLock</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Lock.Common.html#LockMode"><span class="hs-identifier hs-type">LockMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-53"></span><span id="hLock"><span class="annot"><span class="annottext">hLock :: Handle -&gt; LockMode -&gt; IO ()
</span><a href="GHC.IO.Handle.Lock.html#hLock"><span class="hs-identifier hs-var hs-var">hLock</span></a></span></span><span> </span><span id="local-6989586621679558095"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679558095"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679558094"><span class="annot"><span class="annottext">LockMode
</span><a href="#local-6989586621679558094"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO Bool -&gt; IO ()
forall (f :: * -&gt; *) a. Functor f =&gt; f a -&gt; f ()
</span><a href="Data.Functor.html#void"><span class="hs-identifier hs-var">void</span></a></span><span> </span><span class="annot"><span class="annottext">(IO Bool -&gt; IO ()) -&gt; IO Bool -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; LockMode -&gt; Bool -&gt; IO Bool
</span><a href="GHC.IO.Handle.Lock.Windows.html#lockImpl"><span class="hs-identifier hs-var">lockImpl</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679558095"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hLock&quot;</span></span><span> </span><span class="annot"><span class="annottext">LockMode
</span><a href="#local-6989586621679558094"><span class="hs-identifier hs-var">mode</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-54"></span><span>
</span><span id="line-55"></span><span class="hs-comment">-- | Non-blocking version of 'hLock'.</span><span>
</span><span id="line-56"></span><span class="hs-comment">--</span><span>
</span><span id="line-57"></span><span class="hs-comment">-- @since 4.10.0.0</span><span>
</span><span id="line-58"></span><span class="annot"><a href="GHC.IO.Handle.Lock.html#hTryLock"><span class="hs-identifier hs-type">hTryLock</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Lock.Common.html#LockMode"><span class="hs-identifier hs-type">LockMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-59"></span><span id="hTryLock"><span class="annot"><span class="annottext">hTryLock :: Handle -&gt; LockMode -&gt; IO Bool
</span><a href="GHC.IO.Handle.Lock.html#hTryLock"><span class="hs-identifier hs-var hs-var">hTryLock</span></a></span></span><span> </span><span id="local-6989586621679558092"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679558092"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679558091"><span class="annot"><span class="annottext">LockMode
</span><a href="#local-6989586621679558091"><span class="hs-identifier hs-var">mode</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; LockMode -&gt; Bool -&gt; IO Bool
</span><a href="GHC.IO.Handle.Lock.Windows.html#lockImpl"><span class="hs-identifier hs-var">lockImpl</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679558092"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hTryLock&quot;</span></span><span> </span><span class="annot"><span class="annottext">LockMode
</span><a href="#local-6989586621679558091"><span class="hs-identifier hs-var">mode</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-60"></span><span>
</span><span id="line-61"></span><span class="hs-comment">-- | Release a lock taken with 'hLock' or 'hTryLock'.</span><span>
</span><span id="line-62"></span><span class="hs-comment">--</span><span>
</span><span id="line-63"></span><span class="hs-comment">-- @since 4.11.0.0</span><span>
</span><span id="line-64"></span><span class="annot"><a href="GHC.IO.Handle.Lock.html#hUnlock"><span class="hs-identifier hs-type">hUnlock</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-65"></span><span id="hUnlock"><span class="annot"><span class="annottext">hUnlock :: Handle -&gt; IO ()
</span><a href="GHC.IO.Handle.Lock.html#hUnlock"><span class="hs-identifier hs-var hs-var">hUnlock</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; IO ()
</span><a href="GHC.IO.Handle.Lock.Windows.html#unlockImpl"><span class="hs-identifier hs-var">unlockImpl</span></a></span><span>
</span><span id="line-66"></span><span>
</span><span id="line-67"></span><span class="hs-comment">----------------------------------------</span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span></pre></body></html>